/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.table.model;

import javax.swing.table.AbstractTableModel;
import model.Item;

/**
 *
 * @author Martin Mohr Pedersen
 */
public class ItemTableModel extends AbstractTableModel {

    private String[] colNames = {"Vare Nr.", "Vare Navn", "Grund-pris", "Pris"};
    private Class[] colTypes = {java.lang.String.class, java.lang.String.class,
        java.lang.Double.class, java.lang.Double.class};
    
    private Item[] items;

    public ItemTableModel() {
        super();
        
        setItems(new Item[0]);
        
    }
    
    public void setItems(Item[] items) {
        this.items = items;
    }

    @Override
    public int getRowCount() {
        return items.length;
    }

    @Override
    public int getColumnCount() {
        return colNames.length;
    }

    @Override
    public String getColumnName(int index) {
        return colNames[index];
    }

    @Override
    public Class getColumnClass(int index) {
        return colTypes[index];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Item item = getItemAtIndex(rowIndex);

        switch (columnIndex) {
            case 0:
                return item.getItemNo();
            case 1:
                return item.getName();
            case 2:
                return item.getPrice();
            case 3:
                return item.getTotalPrice();
            default:
                return null;
        }
    }

    public Item getItemAtIndex(int index) {
        return items[index];
    }
}
